<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTorneosTable extends Migration {
	
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up() {
		//
		Schema::create ( "torneos", function ($table) {
			$table->increments ( 'id' );
			$table->string ( 'titulo' );
			$table->longText ( 'descripcion' );
			$table->string ( 'password', 200 )->nullable();
			$table->integer ( 'plazas' );
			$table->integer ( 'campo_id' )->unsigned ();
			$table->foreign ( 'campo_id' )->references ( 'id' )->on ( 'campos' )->onDelete('cascade');
			$table->integer ( 'user_id' )->unsigned ();
			$table->foreign ( 'user_id' )->references ( 'id' )->on ( 'users' )->onDelete('cascade');
			$table->integer ( 'duracion' );
			$table->dateTime ( 'fecha' );
			
			$table->timestamps ();
		} );
	}
	
	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down() {
			
		if(Schema::hasTable('torneos')){
			Schema::table( 'torneos', function ($table) {
				$table->dropForeign ( 'torneos_user_id_foreign' );
				$table->dropForeign ( 'torneos_campo_id_foreign' );
			});
		}
		
		Schema::dropIfExists( "torneos" );
	}
}
